//
//  MapResultsCell.m
//  TongGuanLease
//
//  Created by Henghuitong on 2022/6/14.
//

#import "MapResultsCell.h"
#import "MapResultsModel.h"

@implementation MapResultsCell

+ (instancetype)mapResultsCellWithTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MapResultsCell *cell = [tableView dequeueReusableCellWithIdentifier:MapResultsCellID forIndexPath:indexPath];
   
    return cell;
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
       
        self.backgroundColor = [UIColor whiteColor];
    
        [self setUpCellUI];
        
    }
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
}

#pragma mark ————— 初始化页面 —————

-(void)setUpCellUI
{
    [self.contentView  addSubview:self.icon];
    [self.contentView  addSubview:self.checkImgView];
    [self.contentView  addSubview:self.nameLab];
    [self.contentView  addSubview:self.addressLab];
    [self.contentView addSubview:self.line];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(RatioWidth(16));
        make.height.mas_equalTo(RatioWidth(21));
        make.left.mas_equalTo(RatioWidth(15));

    }];

    [self.checkImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.width.height.mas_equalTo(RatioWidth(16));
        make.right.mas_equalTo(-RatioWidth(15));
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(RatioWidth(15));
        make.right.mas_equalTo(self.checkImgView.mas_left).offset(-RatioWidth(5));
        make.top.mas_equalTo(RatioWidth(10));
        make.bottom.mas_equalTo(self.contentView.mas_centerY);
    }];
    [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(RatioWidth(15));
        make.right.mas_equalTo(self.checkImgView.mas_left).offset(-RatioWidth(5));
        make.top.mas_equalTo(self.nameLab.mas_bottom);
        make.bottom.mas_equalTo(self.contentView).offset(-RatioWidth(10));
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(RatioWidth(0.5));
    }];
    
}


#pragma mark -
-(void)setModel:(MapResultsModel *)model
{
    _model = model;
    
    self.nameLab.text = model.name;
    self.addressLab.text = model.detailedAddress;
    
    if(model.isCheck == YES)
    {
        self.icon.image = [UIImage imageNamed:@"map_location_icon"];
        self.checkImgView.image = [UIImage imageNamed:@"error_single_check_icon"];

    }else
    {
        self.icon.image = [UIImage imageNamed:@"map_location_icon_un"];
        self.checkImgView.image = [UIImage imageNamed:@"single_uncheck_icon"];
    }
}

#pragma mark -

-(UIImageView *)icon
{
    if(!_icon)
    {
        _icon = [[UIImageView alloc] init];
        _icon.backgroundColor = [UIColor clearColor];
        _icon.image = [UIImage imageNamed:@"map_location_icon_un"];
    }
    return _icon;
}

-(UIImageView *)checkImgView
{
    if(!_checkImgView)
    {
        _checkImgView = [[UIImageView alloc] init];
        _checkImgView.backgroundColor = [UIColor clearColor];
        _checkImgView.image = [UIImage imageNamed:@"single_uncheck_icon"];
    }
    return _checkImgView;
}

-(UILabel *)nameLab
{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc]init];
        _nameLab.backgroundColor = [UIColor clearColor];
        _nameLab.textColor = [UIColor blackColor];
        _nameLab.font = TGMediumAFont(18);
        _nameLab.textAlignment = NSTextAlignmentLeft;
        
//        _nameLab.text= @"中国南州阿棉";
    }
    return _nameLab;
}

-(UILabel *)addressLab
{
    if (!_addressLab) {
        _addressLab = [[UILabel alloc]init];
        _addressLab.backgroundColor = [UIColor clearColor];
        _addressLab.textColor = [UIColor grayColor];
        _addressLab.font = TGMediumAFont(13);
        _addressLab.textAlignment = NSTextAlignmentLeft;
//        _addressLab.text= @"河南郑州荥阳市";
    }
    return _addressLab;
}
-(UIImageView *)line
{
    if (!_line) {
        _line = [[UIImageView alloc] init];
        _line.backgroundColor = SeparatorColor1;
    }
    return _line;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
